package com.woorigil.social.domain.flower;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FlowerService {
	@Autowired FlowerDao flowerDao;
	@Autowired FlowerCategoryDao flowerCategoryDao;
	@Autowired TagDao tagDao;
	@Autowired FlowerTagRefDao flowerTagRefDao;
	
	public List<FlowerView> findAllFlower() {
		FlowerCondition condition = new FlowerCondition();
		List<Flower> flowers = flowerDao.search(condition);
		
		List<FlowerView> flowerViews = new ArrayList<FlowerView>();
		for (Flower flower : flowers) {
			Category category = flowerCategoryDao.select(flower.getCategoryId());
			List<Tag> tags = tagDao.selectListByFlowerId(flower.getId());
			flowerViews.add(new FlowerView(flower, category, tags));
		}
		
		return flowerViews;
	}

	public List<Category> findAllCategory() {
		return flowerCategoryDao.search();
	}
	
	public List<Tag> findAllTag() {
		return tagDao.search();
	}
	
	public List<FlowerTagRef> findFlowerTagRefByFlowerId(int flowerId) {
		return flowerTagRefDao.selectListByFlowerId(flowerId);
	}
	
	public List<FlowerTagRef> findFlowerTagRefByTagId(int tagId) {
		return flowerTagRefDao.selectListByTagId(tagId);
	}

	public List<FlowerTagRef> findAllFlowerTagRef() {
		return flowerTagRefDao.search();
	}
}
